import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import babel from "@rollup/plugin-babel";
import replace from "@rollup/plugin-replace";
import terser from "@rollup/plugin-terser";
import postcss from "rollup-plugin-postcss";

export default {
  input: "index.jsx", // 入口
  output: {
    file: "dist/bundle.js",
    format: "iife", // 浏览器直接引用
    name: "MyApp",
    sourcemap: true,
  },
  plugins: [
    replace({
      "process.env.NODE_ENV": JSON.stringify("production"),
      preventAssignment: true,
    }),
    resolve({ extensions: [".js", ".jsx"] }),
    commonjs(),
    babel({
      babelHelpers: "bundled",
      exclude: "node_modules/**",
      extensions: [".js", ".jsx"],
    }),
    postcss({ extract: false }), // true 会单独抽离 css 文件
    terser(),
  ],
};
// rollup --config ./rollup.config.mjs
// rollup --config rollup.config.dev.mjs
